<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "set_user_up".
 *
 * @property int $id
 * @property float|null $vip2
 * @property float|null $vip3
 * @property int $vip3_2 配几个达人
 * @property float $vip1_vip1_score
 * @property float $vip1_vip2_balance
 * @property float $vip1_vip2_score
 * @property float $vip1_vip2_product
 * @property float $vip1_vip3_balance
 * @property float $vip1_vip3_score
 * @property float $vip1_vip3_product
 * @property float $vip2_vip1_score
 * @property float $vip2_vip2_balance
 * @property float $vip2_vip2_score
 * @property float $vip2_vip2_product
 * @property float $vip2_vip3_balance
 * @property float $vip2_vip3_score
 * @property float $vip2_vip3_product
 * @property float $vip3_vip1_score
 * @property float $vip3_vip2_balance
 * @property float $vip3_vip2_score
 * @property float $vip3_vip2_product
 * @property float $vip3_vip3_balance
 * @property float $vip3_vip3_score
 * @property float $vip3_vip3_product
 */
class SetUserUp extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'set_user_up';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['vip2', 'vip3', 'vip1_vip1_score', 'vip1_vip2_balance', 'vip1_vip2_score', 'vip1_vip2_product', 'vip1_vip3_balance', 'vip1_vip3_score', 'vip1_vip3_product', 'vip2_vip1_score', 'vip2_vip2_balance', 'vip2_vip2_score', 'vip2_vip2_product', 'vip2_vip3_balance', 'vip2_vip3_score', 'vip2_vip3_product', 'vip3_vip1_score', 'vip3_vip2_balance', 'vip3_vip2_score', 'vip3_vip2_product', 'vip3_vip3_balance', 'vip3_vip3_score', 'vip3_vip3_product'], 'number'],
            [['vip3_2'], 'integer'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'vip2' => 'Vip 2',
            'vip3' => 'Vip 3',
            'vip3_2' => 'Vip 3  2',
            'vip1_vip1_score' => 'Vip 1 Vip 1 Score',
            'vip1_vip2_balance' => 'Vip 1 Vip 2 Balance',
            'vip1_vip2_score' => 'Vip 1 Vip 2 Score',
            'vip1_vip2_product' => 'Vip 1 Vip 2 Product',
            'vip1_vip3_balance' => 'Vip 1 Vip 3 Balance',
            'vip1_vip3_score' => 'Vip 1 Vip 3 Score',
            'vip1_vip3_product' => 'Vip 1 Vip 3 Product',
            'vip2_vip1_score' => 'Vip 2 Vip 1 Score',
            'vip2_vip2_balance' => 'Vip 2 Vip 2 Balance',
            'vip2_vip2_score' => 'Vip 2 Vip 2 Score',
            'vip2_vip2_product' => 'Vip 2 Vip 2 Product',
            'vip2_vip3_balance' => 'Vip 2 Vip 3 Balance',
            'vip2_vip3_score' => 'Vip 2 Vip 3 Score',
            'vip2_vip3_product' => 'Vip 2 Vip 3 Product',
            'vip3_vip1_score' => 'Vip 3 Vip 1 Score',
            'vip3_vip2_balance' => 'Vip 3 Vip 2 Balance',
            'vip3_vip2_score' => 'Vip 3 Vip 2 Score',
            'vip3_vip2_product' => 'Vip 3 Vip 2 Product',
            'vip3_vip3_balance' => 'Vip 3 Vip 3 Balance',
            'vip3_vip3_score' => 'Vip 3 Vip 3 Score',
            'vip3_vip3_product' => 'Vip 3 Vip 3 Product',
        ];
    }

    public static function getLastOne()
    {
        $model = self::find()
            ->orderBy(['id' => SORT_DESC])
            ->one();

        if (!$model) {
            $model = new self();
        }

        return $model;
    }

    public static function saveData($data)
    {
        $model = self::getLastOne();

        if ($model->load(['SetUserUp' => $data]) && $model->save()) {
            return true;
        }
    }
}
